#define DEBUG
#include <cstdio>
#include <cstring>

using namespace std;

const int maxn=100;

class Automaton {
public:
  int n, m, ind[2*maxn+1], to[4*maxn*maxn+1], link[4*maxn*maxn+1], f[2*maxn+1][maxn+1];
  char val[4*maxn*maxn+1];

  void init() {
    n = m = 0;
    memset(ind, 0, sizeof ind);
  }

  void debug() {
    for (int i=1; i<=n; i++) {
      for (int j=ind[i]; j; j=link[j]) {
        printf("%d %d %c\n", i, to[j], val[j]);
      }
    }
  }

  void addSide(int u, int v, char c=0) {
    m++;
    to[m] = v;
    val[m] = c;
    link[m] = ind[u];
    ind[u] = m;
  }

  int build(char s[], int l, int r, int last) {
    int st=++n, ed=++n;
    addSide(last, st);
    int mid=0, lv=0;
    char opt=0;
    for (int i=l; i<=r; i++) {
      if (s[i]=='(') lv++;
      if (s[i]==')') lv--;
      if (lv==0 && s[i]=='|') {
        opt=s[i], mid=i;
        break;
      }
    }
    if (opt=='|') {
      addSide(build(s, l, mid-1, st), ed);
      addSide(build(s, mid+1, r, st), ed);
    } else {
      int la=st, lv=0;
      for (int i=l; i<=r; i++) {
        if (s[i]=='(') {
          int j;
          lv++;
          for (j=i+1; lv; j++) {
            if (s[j]=='(') lv++;
            if (s[j]==')') lv--;
          }
          j--;
          if (s[j+1]=='+' || s[j+1]=='*') {
            int tst=++n, ted=++n;
            addSide(la, tst);
            addSide(build(s, i+1, j-1, tst), ted);
            addSide(ted, tst);
            la = s[j+1]=='+' ? ted : tst;
            i = j+1;
          } else {
            la = build(s, i+1, j-1, la);
            i = j;
          }
        } else {
          int tst=++n, ted=++n;
          addSide(la, tst);
          addSide(tst, ted, s[i]);
          if (s[i+1]=='*' || s[i+1]=='+') {
            addSide(ted, tst);
            la = s[i+1]=='+' ? ted : tst;
            i++;
          } else {
            la = ted;
          }
        }
      }
      addSide(la, ed);
    }
    return ed;
  }

  bool run(int st, int ed, char *s, int p) {
    if (f[st][p]) {
      return f[st][p]==1;
    }
    if (st==ed) {
      f[st][p] = (s[p] && !s[p+1]) ? 1 : 2;
      return f[st][p]==1;
    }

    bool flag=false;
    f[st][p] = 2;
    for (int i=ind[st]; !flag && i; i=link[i]) {
      if (val[i]) {
        if (s[p+1]==val[i]) {
          flag = run(to[i], ed, s, p+1);
        }
      } else {
        flag = run(to[i], ed, s, p);
      }
    }
    f[st][p] = flag ? 1 : 2;
    return flag;
  }

  bool match(int st, int ed, char *s) {
    memset(f, 0, sizeof f);
    return run(st, ed, s, 0);
  }
};

int main() {
#ifdef DEBUG
  freopen("src.in", "r", stdin);
  freopen("src.out", "w", stdout);
#endif

  static Automaton am;
  static char r[maxn+2], str[maxn+2];
  for (; scanf("%s %s", r+1, str+1)!=EOF;) {
    int rn=strlen(r+1);
    am.init();
    int st = am.n = 1, ed = am.build(r, 1, rn, 1);
#ifdef DEBUG
    // am.debug();
#endif
    printf(am.match(st, ed, str) ? "Yes\n" : "No\n");
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
